#ifndef SHIPOBJECT_H
#define SHIPOBJECT_H

#include "shipobject.h"

#include <string>
#include <sstream>
#include <QtGui>

using namespace std;

// The ancestor of all ship objects in the world
class ShipObject {
    int id;
    int row, col;
    string image;
    bool selected;
    bool orientationPortrait;
    bool sunk;
    int numHits;

    static int nextId;
protected:
    int hp;
public:
    //default contstructor
    ShipObject() {}

    ShipObject(int initRow, int initCol, string initImg, int initHp, bool initPortrait):
        row(initRow), col(initCol), image(initImg), hp(initHp), orientationPortrait(initPortrait) {
        id = ++nextId;
        numHits = 0;
        sunk = false;
    }

    ShipObject(int newHp, int newCol, int newRow, bool initPortrait):
        hp(newHp), col(newCol), row(newRow), orientationPortrait(initPortrait), numHits(0) {
    sunk = false;
    }

    virtual bool isBlocker() { return true; }

    virtual string toString() {
        stringstream sstrm;
        sstrm  << col << "\n" << row << "\n" << image << "\n" << selected << "\n" << orientationPortrait <<
                 "\n" << sunk << "\n" << numHits << "\n" << hp << "\n";
        return sstrm.str();
    }

    //accessors

    int getId() { return id; }
    int getRow() { return row; }
    int getCol() { return col; }
    int getHp() { return hp; }
    QString getImage() { return QString::fromStdString(image); }
    bool isSelected() { return selected; }
    bool isPortrait() { return orientationPortrait; }
    int getNumHits() { return numHits; }
    bool isSunk() { return sunk;}
    void setSunk(bool newbool) { sunk = newbool;}

    void setRow(int newRow) { row = newRow; }
    void setCol(int newCol) { col = newCol; }
    void setImage(const string& newImg) { image = newImg; }
    void setHp(const int& newHp) { hp = newHp; }    
    void setSelected(bool newselection) { selected = newselection; }
    void setPortrait(bool newbool) { orientationPortrait = newbool; }
    void incrementNumHits() { ++numHits; }
    void setNumHits(const int& newNum) { numHits = newNum; }
    void decHp() { --hp;}
    void sinkShip() { sunk = true; }

    //test if a given coordinate hits this ship
    bool testHit(int row, int col) const;

    //test if a given ship overlaps with this ship
    bool overlaps(const ShipObject &s) const;

    //for save/load
    void save();
    void load();

};

#endif // SHIPOBJECT_H
